//
//  BusinessWhsEditWhsViewController.m
//  HAODE
//
//  Created by panquanReabam.com on 16/1/26.
//  Copyright © 2016年 reabam.com. All rights reserved.
//

#import "TheEditingViewController.h"

#import "HAODEsingleton.h"
#import "UIViewExt.h"
#import "HttpRequest.h"

@interface TheEditingViewController ()<UISearchBarDelegate,UITextFieldDelegate>

@end

@implementation TheEditingViewController

{
    UISearchBar *search;
    HAODEsingleton* commdity;
    NSMutableArray*code;
    NSMutableArray*content;
    UITextField*whsTextFied;
    UIButton*jiantou;
}

@synthesize alt = alt;


-(void)viewDidLoad{
    
    [super viewDidLoad];
}
-(void)BackAction:(UIButton *)sender{
    
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidDisappear:(BOOL)animated

{
    
    [super viewDidDisappear:animated];
 
    self.navigationController.delegate = nil;
    
}



-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.font=[UIFont systemFontOfSize:13];
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    
    self.title=self.titleName;
    commdity=[HAODEsingleton shared];
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                     [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1.0],
                                                                     UITextAttributeTextColor,
                                                                     [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1],
                                                                     UITextAttributeTextShadowColor,
                                                                     [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
                                                                     UITextAttributeTextShadowOffset,
                                                                     [UIFont fontWithName:@"Helvetica Neue" size:tetlefot],
                                                                     UITextAttributeFont,nil]];
    
    
    
    
    
    
    
    
    
    self.view.backgroundColor=zuiqianhuicolor;
    
    
    
    if ([self.sat isEqualToString:@"Sex"]) {
        UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 64+10, ScreenWidth, 100)];
        view.backgroundColor=[UIColor whiteColor];
        view.layer.borderWidth = 0.35;
        view.layer.borderColor = qianhuicolor.CGColor;
        [self.view addSubview:view];
        
        
        UIButton*nan = [[UIButton alloc] initWithFrame:CGRectMake(15, 0.0,  ScreenWidth, 50)];
        [nan setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [nan setTitle:@"男" forState:UIControlStateNormal];
        nan.titleLabel.font=[UIFont systemFontOfSize:16];
        nan.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
        [nan addTarget:self action:@selector(nan:) forControlEvents:UIControlEventTouchUpInside];
        
        [view addSubview:nan];
        UILabel*line=[[UILabel alloc]initWithFrame:CGRectMake(0, 50, ScreenWidth, 0.35)];
        line.backgroundColor=qianhuicolor;
        [view addSubview:line];
        
        UIButton*nu = [[UIButton alloc] initWithFrame:CGRectMake(15, 50,  ScreenWidth, 50)];
        [nu setTitleColor:[UIColor blackColor]  forState:UIControlStateNormal];
        [nu setTitle:@"女" forState:UIControlStateNormal];
        nu.titleLabel.font=[UIFont systemFontOfSize:16];
        nu.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
        [nu addTarget:self action:@selector(nu:) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:nu];

        if ( [commdity.Sex  isEqualToString: @"男"]) {
            jiantou = [[UIButton alloc]init];
            jiantou.frame = CGRectMake(ScreenWidth-45,10, 30, 30);
            [jiantou setImage:[UIImage imageNamed:@"huiyuan_gou"] forState:UIControlStateNormal];
            [view addSubview:jiantou];
        }else{
            jiantou = [[UIButton alloc]init];
            jiantou.frame = CGRectMake(ScreenWidth-45,10+50, 30, 30);
            [jiantou setImage:[UIImage imageNamed:@"huiyuan_gou"] forState:UIControlStateNormal];
            [view addSubview:jiantou];
        
        }
       

    }else{
    
        UIButton*tianjiaBtn = [[UIButton alloc] initWithFrame:CGRectMake(30, 0.0,  35,35)];
        [tianjiaBtn setTitleColor:luseColor forState:UIControlStateNormal];
        [tianjiaBtn setTitle:@"保存" forState:UIControlStateNormal];
        tianjiaBtn.titleLabel.font=[UIFont systemFontOfSize:16];
        [tianjiaBtn addTarget:self action:@selector(addProduct:) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem* myBtnBtn = [[UIBarButtonItem alloc] initWithCustomView:tianjiaBtn];
        self.navigationItem.rightBarButtonItem = myBtnBtn;

    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 64+10, ScreenWidth, 50)];
    view.backgroundColor=[UIColor whiteColor];
    view.layer.borderWidth = 0.35;
    view.layer.borderColor = qianhuicolor.CGColor;
    [self.view addSubview:view];
    
    
   
    whsTextFied=[[UITextField alloc]initWithFrame:CGRectMake(15, 0, ScreenWidth-30,  50)];
    whsTextFied.borderStyle = UITextBorderStyleNone;
    whsTextFied.font = [UIFont systemFontOfSize: 15];
    whsTextFied.textColor=[UIColor blackColor];
    whsTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
    whsTextFied.text=self.conten;
    [whsTextFied setUserInteractionEnabled:YES];
    whsTextFied.delegate = self;
    whsTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
    [view addSubview:whsTextFied];
    }
    
    
    UIView* myToolBar=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, viewheight)];
    myToolBar.backgroundColor=jianpancolor;
    UIButton*  tubtnDone=[[UIButton alloc]initWithFrame:CGRectMake(logoX,logoY, logoheight, logowidth)];
    [tubtnDone setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [tubtnDone addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:tubtnDone];
    UIButton*btnDone111=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width - 55, 12, 40, 16)];
    [btnDone111 setTitle:@"确定" forState:UIControlStateNormal];
    [btnDone111 setTitleColor:jianpancolor1 forState:UIControlStateNormal];
    btnDone111 .titleLabel .font=[UIFont systemFontOfSize:daxiao];
    [btnDone111 addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:btnDone111];
    myToolBar.alpha=alp;
    UIButton* dabtn=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width-60, 0, 60, 40)];
    [dabtn addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:dabtn];
    
    whsTextFied.inputAccessoryView = myToolBar;
    
    
    
    
}

-(void)OnTapDone{
    
    [whsTextFied resignFirstResponder];
    
    
}

-(void)nan:(UIButton*)sender{
commdity.gengxin=@"";
 commdity.Sex=@"男";
jiantou.frame = CGRectMake(ScreenWidth-45,10, 30, 30);
[self.navigationController popViewControllerAnimated:YES];


}
-(void)nu:(UIButton*)sender{
commdity.gengxin=@"";
 commdity.Sex=@"女";
jiantou.frame = CGRectMake(ScreenWidth-45,10+50, 30, 30);
[self.navigationController popViewControllerAnimated:YES];

}
-(void)addProduct:(UIButton*)sender{
    
    commdity.gengxin=@"";
    
    if ([self.sat isEqualToString:@"userName"]) {
        commdity.userName=whsTextFied.text;
    }
    if ([self.sat isEqualToString:@"Sex"]) {
        commdity.Sex=whsTextFied.text;
    }
    if ([self.sat isEqualToString:@"Memo"]) {
        commdity.Memo=whsTextFied.text;
    }
    if ([self.sat isEqualToString:@"Phone"]) {
        commdity.Phone=whsTextFied.text;
        
    }
    [self.navigationController popViewControllerAnimated:YES];
    
    
    
    
    
    
    
    
    
}
- (void)showAlertWait
{
    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
    
}

- (void)showAlertMessage:(NSString *)msg

{
    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
}
- (void)hideAlert
{
    if (alt != nil)
    {
        [alt dismissWithClickedButtonIndex:0 animated:YES];
        alt = nil;
    }
}

@end
